<%-- 
    Document   : customer-list
    Created on : 24.4.2011, 17:30:55
    Author     : dandelion8
--%>

<%@page import="jlibrarian.entities.Customer"%>
<%@page import="java.util.Collection"%>
<%@page import="jlibrarian.interfaces.CustomerManager"%>
<%@page import="jlibrarian.DbManager"%>
<%@page import="jlibrarian.CustomerManagerImpl"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    CustomerManager cm = new CustomerManagerImpl(DbManager.getDataSource());
    Collection<Customer> customers = cm.getAllCustomers();
%>

<!doctype html>

<html lang="cs">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/shared/style.css" />
        <title>Seznam zákazníků</title>
    </head>
    <body>
        <h1>jLibrarian</h1>
        <div id="main">
            <div id="menu">
                <div class="group">
                    <h3>Zákazníci</h3>
                    <ul>
                        <li><a href="customer-create.jsp">Nový zákazník</a></li>
                        <li><a class="active" href="customer-list.jsp">Zobrazit zákazníky</a></li>
                    </ul>
                </div>
                <div class="group">
                    <h3>Knihy</h3>
                    <ul>
                        <li><a href="book-create.jsp">Nová kniha</a></li>
                        <li><a href="book-list.jsp">Zobrazit knihy</a></li>
                    </ul>
                </div>
            </div>
            <div id="content">
                <!-- start of the content -->


                <h2>Seznam zákazníků</h2>


                <!-- start of the messages -->
                <% if(session != null) out.print(session.getAttribute("messages")); %>
                <% session.setAttribute("messages", "");%>
                <!-- start of the messages -->

                <p>V databázi je <%= customers.size()%> zákazníků.</p>

                <table>
                    <tr>
                        <th>Příjmení</th>
                        <th>Jméno</th>
                        <th>Ulice</th>
                        <th>Město</th>
                    </tr>    
                    <%
                        for (Customer customer : customers) {
                            out.println("<tr>");
                            out.println("<td>" + customer.getSurname() + "</td>");
                            out.println("<td>" + customer.getFirstName() + "</td>");
                            out.println("<td>" + customer.getStreet() + "</td>");
                            out.println("<td>" + customer.getCity() + "</td>");
                            out.println("</tr>");
                        }
                    %>
                </table>


                    <!-- end of the content -->
            </div>
        </div>
    </body>
</html>

